package service.impl;

import com.jfinal.plugin.activerecord.Db;
import com.jfinal.plugin.activerecord.Record;
import com.jfinal.plugin.activerecord.SqlPara;
import model.User;
import service.ICrudDemoServer;

import java.util.List;

/**
 * @Author: Raymond
 * @Date: 2020/7/14 10:27
 * @Description:
 */
public class CrudDemoServerImpl implements ICrudDemoServer {

    public static final CrudDemoServerImpl srv=new CrudDemoServerImpl();


    public List<Record> findAll() {
        String sql = Db.getSql("findall");
        return Db.find(sql);
    }

    public User findOne(int id) {
        SqlPara sql = Db.getSqlPara("findone", id);
        return User.dao.findFirst(sql);
    }

    public String insertone(User user) {

        //SqlPara sql = Db.getSqlPara("insterone",user);
        return String.valueOf(user.save());
    }

    public String delete(int id) {
        return String.valueOf(User.dao.deleteById(id));
    }

    public String update(User user) {
        SqlPara sql = Db.getSqlPara("update",user);
        return String.valueOf(Db.update(sql));
    }
}
